/*
 * Copyright Iain Sproat, 2008
 * 
 *
 */

using System;
using NUnit.Framework;
using Rhino.Mocks;

using FreeBase;
using FreeBase.Fluent;
using FreeBase.Fluent.MQLConverter;
using System.Net;

namespace FreeBase_Test
{
	/// <summary>
	/// 
	/// </summary>
	[TestFixture]
	public class IntegrationTestRead
	{
		
		[Test]
		public void CanReadFromFreebase()
		{
			string queryString = StaticString();
			
			
			IFreebaseClient SUT = new FreebaseClient();  //no credentials passed, as we are only reading
			string returned = SUT.Read( queryString );
			Console.WriteLine( "CanCallFreebase returned => " + returned );
			
			Assert.IsNotNullOrEmpty( returned );
		}
		
		public string CreateExampleQueryString()
		{
			FBQuery fbQuery =
				Freebase.Query
				.Where().Name.Is("The Police")
				.Where().Type.Is("/music/artist")
				.Show.Property("track")
				.Expect.One( "track" ).Which.Meets(
					Freebase.Query
					.Show.OneRecordFor.AllProperties
					.Where().Name.StartsWith("Message")
					.LimitNumberOfResults.To(1)
				);
			IMQLConverter serializer = new FluentMQLConverter();
			return serializer.FluentToMQL( fbQuery );
		}
		
		public string StaticString()
		{
			return "{\"query\":[{\"sort\":\"s0:type.link.timestamp.value\",\"roof_type\":[{\"limit\":6,\"type\":\"/base/engineering/roof_class\",\"name\":null,\"optional\":true,\"id\":null}],\"name\":null,\"total_roof_area_on_plan\":null,\"/common/topic/article\":{\"optional\":true,\"guid\":null,\"limit\":1},\"s0:type\":[{\"link\":[{\"timestamp\":[{\"optional\":true,\"type\":\"/type/datetime\",\"value\":null}],\"type\":\"/type/link\"}],\"type\":\"/type/type\",\"id\":\"/base/engineering/structure_with_roof\"}],\"limit\":60,\"/common/topic/image\":{\"optional\":true,\"limit\":1,\"id\":null},\"covering_material\":[{\"limit\":6,\"type\":\"/base/engineering/roof_covering_material\",\"name\":null,\"optional\":true,\"id\":null}],\"structural_system\":[{\"limit\":6,\"type\":\"/base/engineering/structural_concept\",\"name\":null,\"optional\":true,\"id\":null}],\"type\":\"/base/engineering/structure_with_roof\",\"id\":null}]}";
		}
	}
}
